<?php

namespace paymch\modules\test\controllers;

use Yii;
use yii\web\Controller;

/**
 * RefundController for the `test` module
 */
class RefundController extends Controller {

    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex() {
        $host = Yii::$app->request->hostInfo;

        $client = new \common\components\paymch\MchClient();
        $client->appId = '201710139118';
        $client->rsaPrivateKeyFilePath = Yii::getAlias('@paymch') . '/data/keys/emchpay/rsa_private_key.pem';

        $client->gatewayUrl = $host . '/trade/refund';

        $client->signType = 'RSA2';
        $client->postCharset = 'utf-8';
        $client->apiVersion = '1.0';
        $params = [
            'bizno' => 'SHOP001', //退款单号
            'original_trade_no' => '301171125549713857', //原交易号
            'user_id' => 1,
            'paymode' => 'alipay', //支付时现金使用的支付方式
            'total_amount' => 0.1, //总退款金额（元）
            'point_amount' => 0.1, //总退款中积分部分的金额（元）
            'body' => '退款描述',
        ];
        $data = $client->render($params);

        return \yii\helpers\VarDumper::export($data);
    }

}
